<!DOCTYPE html>
<html lang="en">





<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" type="image/png" href="/img/favicon.png">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="My Personal Website For Blog">
  <meta name="author" content="黄宇辉">
  <meta name="keywords" content="learning note,hexo blog">
  <title>Servlet lifecycle - 欢迎参观小灰灰的网站哟 ヾ(◍°∇°◍)ﾉﾞ ~</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.0/styles/vs2015.min.css" />
  

  


<!-- 主题依赖的图标库，不要自行修改 -->
<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_yg9cfy8wd6.css">

<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_pjno9b9zyxs.css">

<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script  src="/js/utils.js" ></script>
</head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>ANONYMOUS</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                Home
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                Archives
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                Tags
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                About
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="view intro-2" id="background" parallax=true
         style="background: url('/img/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="container text-center white-text fadeInUp">
            <span class="h2" id="subtitle">
              
            </span>

            
              
  <div class="mt-3 post-meta">
    <i class="iconfont icon-date-fill" aria-hidden="true"></i>
    <time datetime="2019-04-06 15:06">
      April 6, 2019 pm
    </time>
  </div>


<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      1.4k 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      22
       分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <div class="post-content mx-auto" id="post">
            
            <article class="markdown-body">
              <h2 id="学习笔记-：Java-Servlet-的生命周期及其解析"><a href="#学习笔记-：Java-Servlet-的生命周期及其解析" class="headerlink" title="学习笔记 ：Java Servlet 的生命周期及其解析"></a>学习笔记 ：Java Servlet 的生命周期及其解析</h2><ul>
<li><p><em>Tomcat v9.0 + JDK 11 + Google Chrome</em></p>
</li>
<li><p><em>Servlet lifecycle</em></p>
</li>
<li><p><img src="/2019/04/06/Servlet-lifecycle/lifecycle.png" srcset="/img/loading.gif" alt=" "></p>
</li>
</ul>
<h3 id="Servlet-2-5-示例"><a href="#Servlet-2-5-示例" class="headerlink" title="Servlet 2.5 示例"></a>Servlet 2.5 示例</h3><ul>
<li><p><em>JSP program</em></p>
<div class="hljs"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">%@</span> <span class="hljs-attr">page</span> <span class="hljs-attr">language</span>=<span class="hljs-string">"java"</span> <span class="hljs-attr">contentType</span>=<span class="hljs-string">"text/html; charset=ISO-8859-1"</span> <span class="hljs-attr">pageEncoding</span>=<span class="hljs-string">"ISO-8859-1"</span>%&gt;</span>
<span class="hljs-meta">&lt;!DOCTYPE html&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
	<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"ISO-8859-1"</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Servlet 2.5<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
	<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
	<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"ServletLifecyle"</span>&gt;</span>doGet : Servlet 3.0<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
		<span class="hljs-comment">&lt;!-- 注意: form的默认提交方式为get --&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
			<span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">action</span>=<span class="hljs-string">"ServletLifecyle"</span> <span class="hljs-attr">method</span>=<span class="hljs-string">"get"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">hr</span>&gt;</span>
				<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"doGet "</span> /&gt;</span>
			<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
			<span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">action</span>=<span class="hljs-string">"ServletLifecyle"</span> <span class="hljs-attr">method</span>=<span class="hljs-string">"post"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>
				<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"doPost"</span> /&gt;</span>
			<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
		<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
	<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span></code></pre></div>
</li>
<li><p><em>Servlet program</em></p>
<div class="hljs"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ServletLifecyle</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">HttpServlet</span> </span>&#123;
	
	
	<span class="hljs-meta">@Override</span>
	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">init</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> ServletException </span>&#123;
		<span class="hljs-comment">// TODO Auto-generated method stub</span>
		<span class="hljs-comment">//super.init();</span>
		System.out.println(<span class="hljs-string">"(Servlet 2.5)init() .."</span>);
	&#125;
	
	<span class="hljs-meta">@Override</span>
	<span class="hljs-function"><span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title">doGet</span><span class="hljs-params">(HttpServletRequest req, HttpServletResponse resp)</span> <span class="hljs-keyword">throws</span> ServletException, IOException </span>&#123;
		<span class="hljs-comment">// TODO Auto-generated method stub</span>
		<span class="hljs-comment">//super.doGet(req, resp);</span>
		System.out.println(<span class="hljs-string">"service() -&gt; doGet() + doPost() .."</span>);
	&#125;
	
	<span class="hljs-meta">@Override</span>
	<span class="hljs-function"><span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title">doPost</span><span class="hljs-params">(HttpServletRequest req, HttpServletResponse resp)</span> <span class="hljs-keyword">throws</span> ServletException, IOException </span>&#123;
		<span class="hljs-comment">// TODO Auto-generated method stub</span>
		<span class="hljs-comment">//super.doPost(req, resp);</span>
		<span class="hljs-keyword">this</span>.doGet(req, resp);
	&#125;
	
	<span class="hljs-meta">@Override</span>
	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">destroy</span><span class="hljs-params">()</span> </span>&#123;
		<span class="hljs-comment">// TODO Auto-generated method stub</span>
		<span class="hljs-comment">//super.destroy();</span>
		System.out.println(<span class="hljs-string">"destory() .."</span>);
	&#125;
&#125;

<span class="hljs-comment">/*

### 1-第一次点击请求连接时Servlet响应的结果如下 :
Apr 05, 2019 10:27:32 PM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/Servlet_basic_lifecycle] is completed
(Servlet 2.5)init() ..                  &lt;—— the result
service() -&gt; doGet() + doPost() ..      &lt;—— the result


### 2-当返回再次点击链接请求时Servlet响应的结果如下 : 
Apr 05, 2019 10:31:05 PM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/Servlet_basic_lifecycle] is completed
(Servlet 2.5)init() ..					&lt;— 第一次点击链接时Servlet的相应结果
service() -&gt; doGet() + doPost() ..		&lt;— 第一次点击链接时Servlet的相应结果
service() -&gt; doGet() + doPost() ..		&lt;— 第二次点击链接时Servlet的相应结果
service() -&gt; doGet() + doPost() ..		&lt;— 第三次点击链接时Servlet的相应结果
service() -&gt; doGet() + doPost() ..		&lt;— 第四次点击链接时Servlet的相应结果
...


### 3-上述来回来点击链接请求后且稍许时间后会发现Servlet自动调用了destory() !!!?
Apr 05, 2019 10:31:05 PM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/Servlet_basic_lifecycle] is completed
(Servlet 2.5)init() ..
service() -&gt; doGet() + doPost() ..
service() -&gt; doGet() + doPost() ..
service() -&gt; doGet() + doPost() ..
service() -&gt; doGet() + doPost() ..
Apr 05, 2019 10:31:41 PM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/Servlet_basic_lifecycle] has started
destory() ..


### 由上述1,2,3可得如下结论 : 
init() :
    默认情况下第一次访问Servlet时会被执行( 只执行一次 ),扩 : 也可以通过配置web.xml文件使得Tomcat启动时自动执行.(详见下述`web.xml`示例)
service() : 
    包括doGet()和doPost(),执行的次数与调用次数成正比.
destory() : 
    关闭Tomcat服务时执行一次.

*/</span></code></pre></div>
</li>
<li><p><em>web.xml</em></p>
</li>
</ul>
<div class="hljs"><pre><code class="hljs xml"><span class="hljs-meta">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">web-app</span> <span class="hljs-attr">xmlns:xsi</span>=<span class="hljs-string">"http://www.w3.org/2001/XMLSchema-instance"</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">"http://xmlns.jcp.org/xml/ns/javaee"</span> <span class="hljs-attr">xsi:schemaLocation</span>=<span class="hljs-string">"http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"WebApp_ID"</span> <span class="hljs-attr">version</span>=<span class="hljs-string">"4.0"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">display-name</span>&gt;</span>Servlet_basic_lifecycle<span class="hljs-tag">&lt;/<span class="hljs-name">display-name</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">welcome-file-list</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">welcome-file</span>&gt;</span>index.html<span class="hljs-tag">&lt;/<span class="hljs-name">welcome-file</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">welcome-file</span>&gt;</span>index.htm<span class="hljs-tag">&lt;/<span class="hljs-name">welcome-file</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">welcome-file</span>&gt;</span>index.jsp<span class="hljs-tag">&lt;/<span class="hljs-name">welcome-file</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">welcome-file</span>&gt;</span>default.html<span class="hljs-tag">&lt;/<span class="hljs-name">welcome-file</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">welcome-file</span>&gt;</span>default.htm<span class="hljs-tag">&lt;/<span class="hljs-name">welcome-file</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">welcome-file</span>&gt;</span>default.jsp<span class="hljs-tag">&lt;/<span class="hljs-name">welcome-file</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">welcome-file-list</span>&gt;</span>
  
  <span class="hljs-comment">&lt;!-- Servlet 2.5 --&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">servlet</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">servlet-name</span>&gt;</span>sameName<span class="hljs-tag">&lt;/<span class="hljs-name">servlet-name</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">servlet-class</span>&gt;</span>pers.huangyuhui.servlet.test.ServletLifecyle<span class="hljs-tag">&lt;/<span class="hljs-name">servlet-class</span>&gt;</span>
		<span class="hljs-comment">&lt;!-- 使得tomcat启动时自动加载init()方法,其数字代表: 当有多个Servlet时,规划其启动的顺序,默认值为`-1`. --&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">load-on-startup</span>&gt;</span>1<span class="hljs-tag">&lt;/<span class="hljs-name">load-on-startup</span>&gt;</span>
	<span class="hljs-tag">&lt;/<span class="hljs-name">servlet</span>&gt;</span>

	<span class="hljs-tag">&lt;<span class="hljs-name">servlet-mapping</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">servlet-name</span>&gt;</span>sameName<span class="hljs-tag">&lt;/<span class="hljs-name">servlet-name</span>&gt;</span>
		<span class="hljs-tag">&lt;<span class="hljs-name">url-pattern</span>&gt;</span>/ServletLifecyle<span class="hljs-tag">&lt;/<span class="hljs-name">url-pattern</span>&gt;</span>
	<span class="hljs-tag">&lt;/<span class="hljs-name">servlet-mapping</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">web-app</span>&gt;</span></code></pre></div>

<div class="hljs"><pre><code class="hljs java">通过在`web.xml`配置文件中添加<span class="hljs-string">'&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;'</span>使得Tomcat启动时自动加载init() !

INFO: At least one JAR was scanned <span class="hljs-keyword">for</span> TLDs yet contained no TLDs. Enable debug logging <span class="hljs-keyword">for</span> <span class="hljs-keyword">this</span> logger <span class="hljs-keyword">for</span> a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
(Servlet <span class="hljs-number">2.5</span>)init() ..	&lt;——— the result.
Apr <span class="hljs-number">06</span>, <span class="hljs-number">2019</span> <span class="hljs-number">2</span>:<span class="hljs-number">31</span>:<span class="hljs-number">09</span> PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler [<span class="hljs-string">"http-nio-8080"</span>]
Apr <span class="hljs-number">06</span>, <span class="hljs-number">2019</span> <span class="hljs-number">2</span>:<span class="hljs-number">31</span>:<span class="hljs-number">09</span> PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler [<span class="hljs-string">"ajp-nio-8009"</span>]
Apr <span class="hljs-number">06</span>, <span class="hljs-number">2019</span> <span class="hljs-number">2</span>:<span class="hljs-number">31</span>:<span class="hljs-number">09</span> PM org.apache.catalina.startup.Catalina start
INFO: Server startup in [<span class="hljs-number">2</span>,<span class="hljs-number">686</span>] milliseconds</code></pre></div>


<h3 id="Servlet-3-0-示例"><a href="#Servlet-3-0-示例" class="headerlink" title="Servlet 3.0 示例"></a>Servlet 3.0 示例</h3><div class="hljs"><pre><code class="hljs java"><span class="hljs-comment">/*
Servlet 3.0 较2.5可以通过注解使Tomcat启动时自动加载Servlet 中的初始化方法: init().

@WebServlet(value="/ServletTest" , loadOnStartup=1)
value : 其为一个字符串数组对象,用于接收多个Servlet,当只有一个Servlet时默认可以不写.
loadOnStartup : 当有多个Servlet时将按照数字大小顺序执行.其默认为-1.
 */</span>

<span class="hljs-meta">@WebServlet</span>(value=<span class="hljs-string">"/ServletTest"</span> , loadOnStartup=<span class="hljs-number">1</span>)
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ServletTest</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">HttpServlet</span> </span>&#123;
	<span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">long</span> serialVersionUID = <span class="hljs-number">1L</span>;

    ······</code></pre></div>


<h3 id="总结深究-待解决的问题"><a href="#总结深究-待解决的问题" class="headerlink" title="总结深究 ( 待解决的问题 )"></a>总结深究 ( 待解决的问题 )</h3><h4 id="发现学习中我并没有关闭Tomcat服务器-但自动执行了销毁方法destory-于是查了一些资料-至今还未发现其答案-我认为-应该是Tomcat新版本的特性吧-超时自动销毁Servlet-但是自动调用Destory-时与Service-时间差也太小了吧-36-秒啊"><a href="#发现学习中我并没有关闭Tomcat服务器-但自动执行了销毁方法destory-于是查了一些资料-至今还未发现其答案-我认为-应该是Tomcat新版本的特性吧-超时自动销毁Servlet-但是自动调用Destory-时与Service-时间差也太小了吧-36-秒啊" class="headerlink" title="发现学习中我并没有关闭Tomcat服务器,但自动执行了销毁方法destory() ! 于是查了一些资料,至今还未发现其答案,我认为 : 应该是Tomcat新版本的特性吧(超时自动销毁Servlet?),但是自动调用Destory()时与Service()时间差也太小了吧 ! 36 秒啊 !"></a>发现学习中我并没有关闭<code>Tomcat</code>服务器,但自动执行了销毁方法<code>destory()</code> ! 于是查了一些资料,至今还未发现其答案,我认为 : 应该是<code>Tomcat</code>新版本的特性吧(超时自动销毁Servlet?),但是自动调用<code>Destory()</code>时与<code>Service()</code>时间差也太小了吧 ! 36 秒啊 !</h4><div class="hljs"><pre><code class="hljs java">### 3-上述来回来点击链接请求后且稍许时间后会发现Servlet自动调用了destory() !!!?
Apr 05, 2019 10:31:05 PM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/Servlet_basic_lifecycle] is completed
(Servlet 2.5)init() ..
service() -&gt; doGet() + doPost() ..       &lt;—— the result
service() -&gt; doGet() + doPost() ..       &lt;—— the result
service() -&gt; doGet() + doPost() ..       &lt;—— the result
service() -&gt; doGet() + doPost() ..       &lt;—— the result
Apr 05, 2019 10:31:41 PM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/Servlet_basic_lifecycle] has started
destory() ..    &lt;—— the result ? what happend ! ? (I'm not close the the Tomcat server now)

······</code></pre></div>

<ul>
<li><em>注意 : <code>&lt;——</code> 是本人后期为便于大家审阅代码加上的.</em></li>
<li><em>后期在不断学习中会完善这些我未知的问题的 ! Stay hungry,Stay foolish.</em></li>
</ul>

            </article>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/Servlet/">Servlet</a>
                    
                      <a class="hover-with-bg" href="/tags/Tomcat/">Tomcat</a>
                    
                      <a class="hover-with-bg" href="/tags/Java/">Java</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" target="_blank" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！</p>
              
              
                <div class="post-prevnext row">
                  <div class="post-prev col-6">
                    
                    
                      <a href="/2019/04/07/Back-up-the-Hexo-blog/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Back up the Hexo blog</span>
                        <span class="visible-mobile">Previous</span>
                      </a>
                    
                  </div>
                  <div class="post-next col-6">
                    
                    
                      <a href="/2019/04/05/Java-Servlet%E5%90%84%E7%89%88%E6%9C%AC%E4%BD%BF%E7%94%A8%E8%AF%A6%E8%A7%A3/">
                        <span class="hidden-mobile">Java Servlet各版本使用详解</span>
                        <span class="visible-mobile">Next</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </div>
                </div>
              
            </div>

            
          </div>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;TOC</p>
  <div id="tocbot"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    
  </main>

  
    <a id="scroll-top-button" href="#" role="button">
      <i class="iconfont icon-arrowup" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">Search</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">keyword</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  

  

  <footer class="mt-5">
  <div class="text-center py-3">
    <div>
      <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a>
      <i class="iconfont icon-love"></i>
      <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener">
        <span>Fluid</span></a>
    </div>
    
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


    

    
  </div>
</footer>

<!-- SCRIPTS -->
<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/js/debouncer.js" ></script>
<script  src="/js/main.js" ></script>

<!-- Plugins -->


  
    <script  src="/js/lazyload.js" ></script>
  



  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>
  <script  src="/js/clipboard-use.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





  <script  src="https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var boardCtn = $('#board-ctn');
      var boardTop = boardCtn.offset().top;

      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: 'article.markdown-body',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        collapseDepth: 0,
        scrollSmooth: true,
        headingsOffset: -boardTop
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc').css('visibility', 'visible');
      }
    });
  </script>



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    var typed = new Typed('#subtitle', {
      strings: [
        '  ',
        "Servlet lifecycle&nbsp;",
      ],
      cursorChar: "_",
      typeSpeed: 70,
      loop: false,
    });
    typed.stop();
    $(document).ready(function () {
      $(".typed-cursor").addClass("h2");
      typed.start();
    });
  </script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "hover",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    var path = "/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      searchFunc(path, 'local-search-input', 'local-search-result');
      this.onclick = null
    }
  </script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />

  <script>
    $('#post img:not(.no-zoom img, img[no-zoom]), img[zoom]').each(
      function () {
        var element = document.createElement('a');
        $(element).attr('data-fancybox', 'images');
        $(element).attr('href', $(this).attr('src'));
        $(this).wrap(element);
      }
    );
  </script>







  
  
    <script>
      !function (e, t, a) {
        function r() {
          for (var e = 0; e < s.length; e++) s[e].alpha <= 0 ? (t.body.removeChild(s[e].el), s.splice(e, 1)) : (s[e].y--, s[e].scale += .004, s[e].alpha -= .013, s[e].el.style.cssText = "left:" + s[e].x + "px;top:" + s[e].y + "px;opacity:" + s[e].alpha + ";transform:scale(" + s[e].scale + "," + s[e].scale + ") rotate(45deg);background:" + s[e].color + ";z-index:99999");
          requestAnimationFrame(r)
        }

        function n() {
          var t = "function" == typeof e.onclick && e.onclick;
          e.onclick = function (e) {
            t && t(), o(e)
          }
        }

        function o(e) {
          var a = t.createElement("div");
          a.className = "heart", s.push({
            el: a,
            x: e.clientX - 5,
            y: e.clientY - 5,
            scale: 1,
            alpha: 1,
            color: c()
          }), t.body.appendChild(a)
        }

        function i(e) {
          var a = t.createElement("style");
          a.type = "text/css";
          try {
            a.appendChild(t.createTextNode(e))
          } catch (t) {
            a.styleSheet.cssText = e
          }
          t.getElementsByTagName("head")[0].appendChild(a)
        }

        function c() {
          return "rgb(" + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + ")"
        }

        var s = [];
        e.requestAnimationFrame = e.requestAnimationFrame || e.webkitRequestAnimationFrame || e.mozRequestAnimationFrame || e.oRequestAnimationFrame || e.msRequestAnimationFrame || function (e) {
          setTimeout(e, 1e3 / 60)
        }, i(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"), n(), r()
      }(window, document);
    </script>
  














</body>
</html>
